<template>
  <div class="main">
    <div class="img_show">
      <img class="img_show_content" src="@/assets/login_show.jpeg" />
    </div>
    <div class="login_content">
      <div class="img_content">
        <img class="img_content_content" src="@/assets/logo.jpg" />
      </div>
      <div class="login_content_show">
        <div class="username_content">
          用户名:<el-input class="username_input" v-model="username" placeholder="请输入内容" style="width: 70%"></el-input>
        </div>
        <div class="password_content">
          密码:<el-input class="psaaword_input" placeholder="请输入密码" v-model="password" show-password style="width: 70%">
          </el-input>
        </div>
        <div class="submit">
          <el-button type="primary" plain @click="onSubmit">登录</el-button>
        </div>
        <div class="spilter"></div>
        <div class="register">
          <el-button type="primary" plain @click="toRegister">注册</el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        username: "",
        password: "",
        width: "300px",
      };
    },
    mounted() {

    },
    methods: {
      onSubmit() {
        console.log("submit")
        this.$axios({
          method: "GET",
          url: "http://81.70.192.34:8088/login",
          params: {
            username: this.username,
            password: this.password,
          },
        }).then((res) => {
          console.log(res)

          if (res.data.code == 200) {
            let data = res.data;
            console.log(data.token)

            //判断token存在
            if (data.token) {
              //保存token
              this.$cookies.set('Authorization', data.token, {
                path: '/',
                maxAge: 60 * 60 * 24 * 7
              });

              //跳转页面
              console.log(res.data.user.position)
              if (res.data.user.position == 0) {
                this.$router.push("/");
              } else {
                this.$router.push("/management");
              }
            } else {
              //token不存在的情况，登录失败
            }
          }
        })
          .catch((error) => {
            console.error(error);
          });
      },
      toRegister() {
        this.$router.push({
          path: "/register",
          query: {},
        });
      },
    },
  };
</script>

<style>
  .main {
    height: 100vh;
    width: 100vw;
    display: flex;
    flex-wrap: wrap;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
  }

  .img_show {
    height: 100vh;
    width: 80vw;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
  }

  .img_show_content {
    max-height: 100vh;
    max-width: 80vw;
  }

  .img_content_content {
    max-height: 30vh;
    max-width: 20vw;
    margin-left: 3vw;
  }

  .login_content {
    height: 100vh;
    width: 20vw;
  }

  .img_content {
    height: 30vh;
    width: 20vw;
    margin-top: 1vh;
  }

  .login_content_show {
    height: 54vh;
    width: 16vw;
    margin-left: 2vw;
    margin-top: 2vh;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
  }

  .username_content {
    margin-left: 1vw;
  }

  .username_input {
    margin-top: 10vh;
  }

  .password_content {
    margin-left: 1vw;
  }

  .psaaword_input {
    margin-top: 3vh;
    margin-left: 1vw;
  }

  .verify_content {
    margin-top: 5vh;
    margin-left: 1vw;
  }

  .verify_code_input {
    margin-top: 4vh;
    margin-left: 1vw;
  }

  .spilter {
    height: 2vh;
    border-bottom: 1px solid #e6e6e6;
  }

  .submit {
    margin-top: 4vh;
    margin-left: 3vw;
  }

  .register {
    margin-top: 2vh;
    margin-left: 3vw;
  }

  .el-button--primary.is-plain {
    width: 10vw;
  }
</style>